home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 April / macformat-049.iso / mac / Shareware Plus / Developers / dropg++ / usr / include / nfs / nqnfs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  7.1 KB  |  199 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1992, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Rick Macklem at The University of Guelph.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  *
  36.  *    @(#)nqnfs.h    8.1 (Berkeley) 6/10/93
  37.  */
  38.  
  39. /*
  40.  * Definitions for NQNFS (Not Quite NFS) cache consistency protocol.
  41.  */
  42.  
  43. /* Tunable constants */
  44. #define    NQ_CLOCKSKEW    3    /* Clock skew factor (sec) */
  45. #define    NQ_WRITESLACK    5    /* Delay for write cache flushing */
  46. #define    NQ_MAXLEASE    60    /* Max lease duration (sec) */
  47. #define    NQ_MINLEASE    5    /* Min lease duration (sec) */
  48. #define    NQ_DEFLEASE    30    /* Default lease duration (sec) */
  49. #define    NQ_RENEWAL    3    /* Time before expiry (sec) to renew */
  50. #define    NQ_TRYLATERDEL    15    /* Initial try later delay (sec) */
  51. #define    NQ_MAXNUMLEASE    2048    /* Upper bound on number of server leases */
  52. #define    NQ_DEADTHRESH    NQ_NEVERDEAD    /* Default nm_deadthresh */
  53. #define    NQ_NEVERDEAD    9    /* Greater than max. nm_timeouts */
  54. #define    NQLCHSZ        256    /* Server hash table size */
  55.  
  56. #define    NQNFS_PROG    300105    /* As assigned by Sun */
  57. #define    NQNFS_VER1    1
  58. #define    NQNFS_EVICTSIZ    156    /* Size of eviction request in bytes */
  59.  
  60. /*
  61.  * Definitions used for saving the "last lease expires" time in Non-volatile
  62.  * RAM on the server. The default definitions below assume that NOVRAM is not
  63.  * available.
  64.  */
  65. #define    NQSTORENOVRAM(t)
  66. #define    NQLOADNOVRAM(t)
  67.  
  68. /*
  69.  * Defn and structs used on the server to maintain state for current leases.
  70.  * The list of host(s) that hold the lease are kept as nqhost structures.
  71.  * The first one lives in nqlease and any others are held in a linked
  72.  * list of nqm structures hanging off of nqlease.
  73.  *
  74.  * Each nqlease structure is chained into two lists. The first is a list
  75.  * ordered by increasing expiry time for nqsrv_timer() and the second is a chain
  76.  * hashed on lc_fh.
  77.  */
  78. #define    LC_MOREHOSTSIZ    10
  79.  
  80. struct nqhost {
  81.     union {
  82.         struct {
  83.             u_short udp_flag;
  84.             u_short    udp_port;
  85.             union nethostaddr udp_haddr;
  86.         } un_udp;
  87.         struct {
  88.             u_short connless_flag;
  89.             u_short connless_spare;
  90.             union nethostaddr connless_haddr;
  91.         } un_connless;
  92.         struct {
  93.             u_short conn_flag;
  94.             u_short conn_spare;
  95.             struct nfssvc_sock *conn_slp;
  96.         } un_conn;
  97.     } lph_un;
  98. };
  99. #define    lph_flag    lph_un.un_udp.udp_flag
  100. #define    lph_port    lph_un.un_udp.udp_port
  101. #define    lph_haddr    lph_un.un_udp.udp_haddr
  102. #define    lph_inetaddr    lph_un.un_udp.udp_haddr.had_inetaddr
  103. #define    lph_claddr    lph_un.un_connless.connless_haddr
  104. #define    lph_nam        lph_un.un_connless.connless_haddr.had_nam
  105. #define    lph_slp        lph_un.un_conn.conn_slp
  106.  
  107. struct nqlease {
  108.     struct nqlease *lc_chain1[2];    /* Timer queue list (must be first) */
  109.     struct nqlease *lc_fhnext;    /* Fhandle hash list */
  110.     struct nqlease **lc_fhprev;
  111.     time_t        lc_expiry;    /* Expiry time (sec) */
  112.     struct nqhost    lc_host;    /* Host that got lease */
  113.     struct nqm    *lc_morehosts;    /* Other hosts that share read lease */
  114.     fsid_t        lc_fsid;    /* Fhandle */
  115.     char        lc_fiddata[MAXFIDSZ];
  116.     struct vnode    *lc_vp;        /* Soft reference to associated vnode */
  117. };
  118. #define    lc_flag        lc_host.lph_un.un_udp.udp_flag
  119.  
  120. /* lc_flag bits */
  121. #define    LC_VALID    0x0001    /* Host address valid */
  122. #define    LC_WRITE    0x0002    /* Write cache */
  123. #define    LC_NONCACHABLE    0x0004    /* Non-cachable lease */
  124. #define    LC_LOCKED    0x0008    /* Locked */
  125. #define    LC_WANTED    0x0010    /* Lock wanted */
  126. #define    LC_EXPIREDWANTED 0x0020    /* Want lease when expired */
  127. #define    LC_UDP        0x0040    /* Host address for udp socket */
  128. #define    LC_CLTP        0x0080    /* Host address for other connectionless */
  129. #define    LC_LOCAL    0x0100    /* Host is server */
  130. #define    LC_VACATED    0x0200    /* Host has vacated lease */
  131. #define    LC_WRITTEN    0x0400    /* Recently wrote to the leased file */
  132. #define    LC_SREF        0x0800    /* Holds a nfssvc_sock reference */
  133.  
  134. struct nqm {
  135.     struct nqm    *lpm_next;
  136.     struct nqhost    lpm_hosts[LC_MOREHOSTSIZ];
  137. };
  138.  
  139. /*
  140.  * Flag bits for flags argument to nqsrv_getlease.
  141.  */
  142. #define    NQL_READ    LEASE_READ    /* Read Request */
  143. #define    NQL_WRITE    LEASE_WRITE    /* Write Request */
  144. #define    NQL_CHECK    0x4        /* Check for lease */
  145. #define    NQL_NOVAL    0xffffffff    /* Invalid */
  146.  
  147. /*
  148.  * Special value for slp for local server calls.
  149.  */
  150. #define    NQLOCALSLP    ((struct nfssvc_sock *) -1)
  151.  
  152. /*
  153.  * Server side macros.
  154.  */
  155. #define    nqsrv_getl(v, l) \
  156.         (void) nqsrv_getlease((v), &nfsd->nd_duration, \
  157.          ((nfsd->nd_nqlflag != 0 && nfsd->nd_nqlflag != NQL_NOVAL) ? nfsd->nd_nqlflag : \
  158.          ((l) | NQL_CHECK)), \
  159.          nfsd, nam, &cache, &frev, cred)
  160.  
  161. /*
  162.  * Client side macros that check for a valid lease.
  163.  */
  164. #define    NQNFS_CKINVALID(v, n, f) \
  165.  ((time.tv_sec > (n)->n_expiry && \
  166.  VFSTONFS((v)->v_mount)->nm_timeouts < VFSTONFS((v)->v_mount)->nm_deadthresh) \
  167.   || ((f) == NQL_WRITE && ((n)->n_flag & NQNFSWRITE) == 0))
  168.  
  169. #define    NQNFS_CKCACHABLE(v, f) \
  170.  ((time.tv_sec <= VTONFS(v)->n_expiry || \
  171.   VFSTONFS((v)->v_mount)->nm_timeouts >= VFSTONFS((v)->v_mount)->nm_deadthresh) \
  172.    && (VTONFS(v)->n_flag & NQNFSNONCACHE) == 0 && \
  173.    ((f) == NQL_READ || (VTONFS(v)->n_flag & NQNFSWRITE)))
  174.  
  175. #define    NQNFS_NEEDLEASE(v, p) \
  176.         (time.tv_sec > VTONFS(v)->n_expiry ? \
  177.          ((VTONFS(v)->n_flag & NQNFSEVICTED) ? 0 : nqnfs_piggy[p]) : \
  178.          (((time.tv_sec + NQ_RENEWAL) > VTONFS(v)->n_expiry && \
  179.            nqnfs_piggy[p]) ? \
  180.            ((VTONFS(v)->n_flag & NQNFSWRITE) ? \
  181.             NQL_WRITE : nqnfs_piggy[p]) : 0))
  182.  
  183. /*
  184.  * List head for timer queue.
  185.  */
  186. extern union nqsrvthead {
  187.     union    nqsrvthead *th_head[2];
  188.     struct    nqlease *th_chain[2];
  189. } nqthead;
  190. extern struct nqlease **nqfhead;
  191. extern u_long nqfheadhash;
  192.  
  193. /*
  194.  * Nqnfs return status numbers.
  195.  */
  196. #define    NQNFS_EXPIRED    500
  197. #define    NQNFS_TRYLATER    501
  198. #define NQNFS_AUTHERR    502
  199.